<?php

namespace process;

use app\service\modbus\ModbusTcpService;
use Workerman\Connection\AsyncTcpConnection;
use Workerman\Crontab\Crontab;

class ModbusTcpTask
{

    public function onWorkerStart()
    {
        // 每秒钟执行一次
        new Crontab('*/10 * * * * *', function(){
            $this->getModbusTcpValue();
        });
    }

    private function getModbusTcpValue()
    {
        $ModbusTcpService = new ModbusTcpService();
        //获取温度
        $data = $ModbusTcpService->getModbusTcpValue(1,0,10);
        if (isset($data['error'])){
            return false;
        }
        return true;
    }



}
